


import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 佳宝文章相关接口
 *
 * allen  2023-12-19
 */

/**
 * 
 * 礼品卡详情接口
 * type:0:文章，1：视频
 */
const queryArticleList = (type, page, limit, cid) => {
  return new Promise((resolve, reject) => {
    get("/api/front/article/list?type=" + type + "&page=" + page + "&limit=" + limit + "&cid=" + cid).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 
 * 热门文章列表
 * 
 */
const queryHotArticleList = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/article/hot/list").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 礼品卡绑定接口
 * data:{
 *   cardNo:"",卡编号
 *   smsCode:"",//短信验证码
 * }
 */
const giftBind = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/gift/oper/bind", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 
 * 礼品卡购买接口
 * data:{
 *   cardId:"",
 * payType:"weixin",
 *   from:"routine"
 * }
 */
const buyCard = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/gift/oper/buy", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 文章详情
 * 
 */
const articleDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/api/front/article/info?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 轮播列表
 * 
 */
const articleBannerList = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/article/banner/list").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 文章分类列表
 * 
 */
const articleCategoryList = (extra) => {
  return new Promise((resolve, reject) => {
    get("/api/front/article/category/list?extra=" + extra).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

module.exports = {
  queryArticleList,
  queryHotArticleList,
  articleCategoryList,
  articleBannerList,
  articleDetail
}

